﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyShopThoiTrang.QuanLyShopThoiTrang_BUS_WS;

namespace QuanLyShopThoiTrang
{
    public partial class TraCuuHoaDonBanHang : Form
    {
        QuanLyHoaDonBanHang qlhdbh = new QuanLyHoaDonBanHang();
        QLSTT_BUSSoapClient ws = new QLSTT_BUSSoapClient();
        public TraCuuHoaDonBanHang()
        {
            InitializeComponent();
        }

        private void TraCuuHoaDonBanHang_Load(object sender, EventArgs e)
        {
            NhanVien temp = new NhanVien();
            temp.MaNhanVien = -1;

            List<NhanVien> listNV = ws.NhanVien_TraCuu(temp);
            comboBox1.DataSource = listNV;
            comboBox1.DisplayMember = "NhanVien_TenDayDu";
        }

        public void Set(QuanLyHoaDonBanHang ql)
        {
            qlhdbh = ql;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HoaDonBanHang hdbh = new HoaDonBanHang();

            if (checkBox1.Checked)
            {
                NhanVien temp = (NhanVien)comboBox1.SelectedItem;
                hdbh.MaNhanVien = temp.MaNhanVien;
            }
            else
                hdbh.MaNhanVien = 0;
            if (textBox1.Text != "")
            {
                if(ws.KiemTraDouble(textBox1.Text))
                    hdbh.HDBH_ThanhTien = double.Parse(textBox1.Text);
                else
                {
                    MessageBox.Show("Thành tiền không hợp lệ");
                    return;
                }
            }
            else
                hdbh.HDBH_ThanhTien = 0;
            if (checkBox2.Checked)
                hdbh.HDBH_NgayLap = dateTimePicker1.Value;
            else
                hdbh.HDBH_NgayLap = null;

            qlhdbh.TraCuu(hdbh);
            Close();

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                comboBox1.Enabled = true;
            else
                comboBox1.Enabled = false;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
                dateTimePicker1.Enabled = true;
            else
                dateTimePicker1.Enabled = false;
        }


    }
}
